package com.lanou.fooddemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.fooddemo.R;
import com.lanou.fooddemo.external.smart_image_view.SmartImageView;
import com.lanou.fooddemo.util.CommonUtil;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Created by dllo on 2015/8/15.
 */
public class NoticeInformationAdapter extends BaseAdapter {
    private List<HashMap<String, String>> dataList;
    private LayoutInflater inflater;
    public NoticeInformationAdapter(Context c, List<HashMap<String, String>> list) {
        inflater = LayoutInflater.from(c);
        dataList = list;
    }
    @Override
    public int getCount() {
        if (CommonUtil.isListNotNull(dataList)) {
            return dataList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.view_notice_list_item, null);
            holder = new Holder();
            holder.iconImageView = (SmartImageView) convertView.findViewById(R.id.noticeItemUserIcImageView);
            holder.titleTextView = (TextView) convertView.findViewById(R.id.noticeItemUserName);
            holder.contentTextView = (TextView) convertView.findViewById(R.id.noticeItemUserSign);

            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        HashMap<String, String> noticeMap = dataList.get(position);
        String title = null;
        String content = null;
        Set<String> keySet = noticeMap.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            title = iterator.next();
        }
        content = noticeMap.get(title);
        holder.titleTextView.setText(title);
        holder.contentTextView.setText(content);
        return convertView;
    }
    class Holder {
        SmartImageView iconImageView;
        TextView titleTextView;
        TextView contentTextView;
    }
}
